/***************************************************************************************************
 *Copyright(C),2010-2016,Sumscope
 *FileName	:  KeyFieldMaker.cpp
 *Author	:  scofined.qi
 *Version	:  1.0
 *Date		:  2017/04/10
 *Desc		:  //用于主要说明此程序文件完成的主要功能
 *Relation :
 *Others	:  //其他内容说明
 *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
 *History	:
 * //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
 ***************************************************************************************************/
#include "KeyFieldMaker.h"

#include "DictType.h"

#define RTL_FIELD_SIZE(type, field) (sizeof(((type*)0)->field))

namespace qb {
namespace ht {
void BondDictKeyMaker::BeforeUpdate(char* record, int size,
                                    const char* recordName, const char* keyName,
                                    int keyffset, int keySize) {
  // BOND_DICT
  // Selective_Code + Group_Name
  BOND_DICT* pdict = (BOND_DICT*)record;
  memset(pdict->Key, 0, RTL_FIELD_SIZE(BOND_DICT, Key));
  FMTBUF(pdict->Key, "%s|%s", pdict->Selective_Code, pdict->Group_Name);
}

void BondHolidayKeyMaker::BeforeUpdate(char* record, int size,
                                       const char* recordName,
                                       const char* keyName, int keyffset,
                                       int keySize) {
  BOND_HOLIDAY* pdict = (BOND_HOLIDAY*)record;
  memset(pdict->Key, 0, RTL_FIELD_SIZE(BOND_HOLIDAY, Key));
  FMTBUF(pdict->Key, "%s|%s|%d", pdict->Country, pdict->Market, pdict->Holiday);
}
void MacroIndexKeyMaker::BeforeUpdate(char* record, int size,
                                      const char* recordName,
                                      const char* keyName, int keyffset,
                                      int keySize) {
  BASSERT(record && size > 0);
  BASSERT(recordName && keyName);
  BASSERT(keyffset >= 0 && keySize > 0);

  DICT_MACRO_INDEX* pdict = (DICT_MACRO_INDEX*)record;
#ifdef WIN32
  __try {
#else
  try {
#endif
    memset(pdict->Key, 0, RTL_FIELD_SIZE(DICT_MACRO_INDEX, Key));
    FMTBUF(pdict->Key, "%s|%d", pdict->Code, pdict->Date);
  }
#ifdef WIN32
  __except (1)
#else
  catch (...)
#endif
  {
    return;
  }
}
}  // namespace ht
}  // namespace qb
